home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / graphics / gnuplot / term / grass.trm < prev    next >
Text File  |  1993-05-31  |  11KB  |  443 lines

  1. /* GNUPLOT - grass.trm */
  2. /*-
  3.  * Copyright (C) 1992,1993. James Darrell McCauley
  4.  *
  5.  * Permission to use, copy, and distribute this software and its
  6.  * documentation for any purpose with or without fee is hereby granted,
  7.  * provided that the above copyright notice appear in all copies and
  8.  * that both that copyright notice and this permission notice appear
  9.  * in supporting documentation.
  10.  *
  11.  * Permission to modify the software is granted, but not the right to
  12.  * distribute the modified code.  Modifications are to be distributed
  13.  * as patches to released version.
  14.  *
  15.  * This software  is provided "as is" without express or implied warranty.
  16.  *
  17.  * This file is included by ../term.c.
  18.  *
  19.  * This terminal driver supports:
  20.  *  GRASS graphics driver
  21.  *
  22.  * AUTHOR
  23.  *  James Darrell McCauley
  24.  *
  25.  * send your comments or suggestions to (grassp-list@moon.cecer.army.mil).
  26.  *
  27.  */
  28. #include <stdio.h>
  29. /* #include "gis.h" */ /* this causes conflicts with things in term.c */
  30.  
  31. #define GRASS_XMAX 1000
  32. #define GRASS_YMAX 1000
  33. #define GRASS_VCHAR 5
  34. #define GRASS_HCHAR 5
  35. #define GRASS_VTIC 3
  36. #define GRASS_HTIC 3
  37.  
  38. #define PNT_SIZE 3
  39. #define TYPE_DOT  -1
  40. #define TYPE_X  0
  41. #define TYPE_PLUS   1
  42. #define TYPE_BOX    2
  43. #define TYPE_DIAMOND    3    /* need type 4 and 5 */
  44. #define TYPE_TRIANGLE 4
  45. #define TYPE_OCTO 5
  46. #define TYPE_ITRIANGLE 6
  47. #define TYPE_FBOX 7
  48. #define TYPE_FTRIANGLE 8
  49. #define TYPE_FITRIANGLE 9
  50. #define TYPE_FOCTO 10
  51.  
  52. int R__curx, R__cury;
  53.  
  54. int yoffset;
  55. int xoffset;
  56. int y_max;
  57. int points_buf_x[PNT_SIZE*PNT_SIZE]; /* for filled point types */
  58. int points_buf_y[PNT_SIZE*PNT_SIZE];
  59.  
  60. GRASS_move (x, y)
  61.   int x, y;
  62. {
  63.   /* R_move_abs (xoffset+x, yoffset-y + y_max); */
  64.   R_move_abs (xoffset+x, yoffset-y);
  65. }
  66.  
  67. cont_abs (x, y)
  68.   int x, y;
  69. {
  70.   /* R_cont_abs (xoffset+x, xoffset-y + y_max); */
  71.   R_cont_abs (xoffset+x, yoffset-y);
  72. }
  73.  
  74. GRASS_options ()
  75. {
  76.   options_null ();        /* no options to begin with */
  77. }
  78.  
  79. GRASS_init ()
  80. {
  81.   char buff[128];
  82.   char window_name[64];
  83.   float size = 3.0;
  84.   int backcolor;
  85.   int dots_per_line;
  86.   int top, b, l, r;
  87.   int textcolor;
  88.   struct termentry *t = &term_tbl[term];
  89.  
  90.   G_gisinit ("g.gnuplot");
  91.  
  92.   R_open_driver ();
  93.  
  94.   D_setup (0); 
  95.  
  96.   if (D_get_cur_wind (window_name))
  97.     G_fatal_error ("No current window");
  98.  
  99.   if (D_set_cur_wind (window_name))
  100.     G_fatal_error ("Current window not available");
  101.  
  102.   /* Set up the screen, conversions, and graphics */
  103.   D_get_screen_window (&top, &b, &l, &r);
  104. /*
  105.   if (D_cell_draw_setup (top, b, l, r))
  106.   {
  107.     sprintf (buff, "Cannot use current window");
  108.     G_fatal_error (buff);
  109.   }
  110. */
  111.   /* D_set_overlay_mode (1); */
  112.  
  113.   /* Figure out where to put text */
  114.  
  115.   R_set_window (top, b, l, r);
  116.   t->xmax = r-l;
  117.   t->ymax = b-top;
  118.   xoffset=l;
  119.   yoffset=b;
  120.  
  121.   dots_per_line = (int) (size / 100.0 * (float) (t->ymax));
  122.   t->v_char = t->h_char = (int) (.8 * (float) dots_per_line);
  123.   R_text_size (t->h_char, t->v_char);
  124.  
  125.   t->v_tic = t->h_tic = 4;
  126.  
  127.   y_max = t->ymax; /* kludge? */
  128.  
  129.   R__curx = R_screen_top ();
  130.   R__cury = R_screen_bot () + yoffset;
  131.  
  132.   D_erase_window();
  133. /*
  134. fprintf(stderr,"**********************************************\n");
  135. fprintf(stderr,"DIAGNOSTIC TERMINAL SETUP\n");
  136. fprintf(stderr,"top = %d\tb = %d\tl = %d\tr = %d\n", top,b,l,r);
  137. fprintf(stderr,"name = %s\n", t->name);
  138. fprintf(stderr,"description = %s\n", t->description);
  139. fprintf(stderr,"xmax = %d\t", (int)t->xmax);
  140. fprintf(stderr,"ymax = %d\n", (int)t->ymax);
  141. fprintf(stderr,"v_char = %d\t", (int)t->v_char);
  142. fprintf(stderr,"h_char = %d\n", (int)t->h_char);
  143. fprintf(stderr,"v_tic = %d\t", (int)t->v_tic);
  144. fprintf(stderr,"h_tic = %d\n", (int)t->h_tic);
  145. fprintf(stderr,"**********************************************\n\n");
  146. */
  147. }
  148.  
  149. GRASS_reset ()
  150. {
  151.   R_standard_color (D_translate_color ("black"));
  152.   /* D_erase_window(); /* don't clear after g.gnuplot is finished */ 
  153.   R_flush ();
  154.   R_stabilize ();
  155.   R_close_driver ();
  156. }
  157.  
  158. GRASS_graphics ()
  159. {
  160.   R_flush ();
  161.   R_stabilize ();
  162.   R_standard_color (D_translate_color ("black"));
  163.   D_erase_window();
  164.   return;
  165. }
  166.  
  167. GRASS_text ()
  168. {
  169.   R_flush ();
  170.   R_stabilize ();
  171.   return;            /* device can't be used as a terminal */
  172. }
  173.  
  174. GRASS_vector (x, y)
  175.   int x, y;
  176. {
  177.   cont_abs (x, y);
  178.   R_flush ();
  179.   R_stabilize ();
  180. }
  181.  
  182. GRASS_linetype (lt)
  183.   int lt;
  184. {
  185.  
  186.   while (lt > 10) lt-=10;
  187.  
  188.   if (lt <= -2)
  189.     R_standard_color (D_translate_color ("gray"));
  190.   else if (lt == -1)
  191.     R_standard_color (D_translate_color ("white"));
  192.   else if (lt == 0)
  193.     R_standard_color (D_translate_color ("red"));
  194.   else if (lt == 1)
  195.     R_standard_color (D_translate_color ("green"));
  196.   else if (lt == 2)
  197.     R_standard_color (D_translate_color ("magenta"));
  198.   else if (lt == 3)
  199.     R_standard_color (D_translate_color ("brown"));
  200.   else if (lt == 4)
  201.     R_standard_color (D_translate_color ("orange"));
  202.   else if (lt == 5)
  203.     R_standard_color (D_translate_color ("yellow"));
  204.   else if (lt == 6)
  205.     R_standard_color (D_translate_color ("blue"));
  206.   else if (lt == 7)
  207.     R_standard_color (D_translate_color ("violet"));
  208.   else if (lt == 8) 
  209.     R_standard_color (D_translate_color ("indigo"));
  210.   else if (lt == 9)
  211.     R_standard_color (D_translate_color ("gray"));
  212.   else /* if (lt == 10) */
  213.     R_standard_color (D_translate_color ("white"));
  214.   R_flush ();
  215.   R_stabilize ();
  216.   return;
  217. }
  218.  
  219. /* originally /usr/grass4/src/display/d.label/cmd/label.c */
  220.  
  221. GRASS_put_text (x, y, str)
  222.   int x, y;
  223.   char *str;
  224. {
  225.  
  226.   if (strlen (str) == 0)
  227.     return;
  228.  
  229.   GRASS_move (x, y);
  230.   /* R_standard_color (D_translate_color ("white")); */
  231.   R_text (str);
  232.   R_flush ();
  233.   R_stabilize ();
  234. }
  235.  
  236. int GRASS_text_angle (ang)
  237. {
  238.   return FALSE;            /* GRASS cannot rotate text */
  239. }
  240.  
  241. int GRASS_justify_text (mode)
  242.   int mode;
  243. {
  244.   return (FALSE);        /* don't mess with this now */
  245. }
  246.  
  247.  
  248. GRASS_point (x, y, point)
  249. {
  250.   switch (point)
  251.   {
  252.   case TYPE_DOT:
  253.     draw_points_dot (x, y);
  254.     break;
  255.   case TYPE_X:
  256.     draw_points_x (x, y);
  257.     break;
  258.   case TYPE_PLUS:
  259.     draw_points_plus (x, y);
  260.     break;
  261.   case TYPE_BOX:
  262.     draw_points_box (x, y);
  263.     break;
  264.   case TYPE_DIAMOND:
  265.     draw_points_diamond (x, y);
  266.     break;
  267.   case TYPE_TRIANGLE:
  268.     draw_points_triangle (x, y);
  269.     break;
  270.   case TYPE_OCTO:
  271.     draw_points_octo (x, y);
  272.     break;
  273.   case TYPE_ITRIANGLE:
  274.     draw_points_itriangle (x, y);
  275.     break;
  276.   case TYPE_FBOX:
  277.     draw_points_fbox (x, y);
  278.     break;
  279.   case TYPE_FTRIANGLE:
  280.     draw_points_ftriangle (x, y);
  281.     break;
  282.   case TYPE_FITRIANGLE:
  283.     draw_points_fitriangle (x, y);
  284.     break;
  285.   case TYPE_FOCTO:
  286.     draw_points_focto (x, y);
  287.     break;
  288.   }
  289. }
  290.  
  291. /* modified from /usr/grass4/src/display/d.points/cmd/main.c */
  292.  
  293. draw_points_dot (x, y)
  294.   int x, y;
  295. {
  296.   GRASS_move (x, y);
  297.   cont_abs (x, y);
  298. }
  299.  
  300. draw_points_diamond (x, y)
  301.   int x, y;
  302. {
  303.   GRASS_move (x, y + PNT_SIZE);
  304.   GRASS_vector (x + PNT_SIZE, y);
  305.   GRASS_vector (x, y - PNT_SIZE);
  306.   GRASS_vector (x - PNT_SIZE, y);
  307.   GRASS_vector (x, y + PNT_SIZE);
  308. }
  309.  
  310. draw_points_box (x, y)
  311.   int x, y;
  312. {
  313.   GRASS_move (x - PNT_SIZE, y - PNT_SIZE);
  314.   GRASS_vector (x - PNT_SIZE, y + PNT_SIZE);
  315.   GRASS_vector (x + PNT_SIZE, y + PNT_SIZE);
  316.   GRASS_vector (x + PNT_SIZE, y - PNT_SIZE);
  317.   GRASS_vector (x - PNT_SIZE, y - PNT_SIZE);
  318. }
  319.  
  320. draw_points_fbox (x, y)
  321.   int x, y;
  322. {
  323.   points_buf_x[0] = xoffset + x - PNT_SIZE; 
  324.   points_buf_y[0]= yoffset - (y + PNT_SIZE);
  325.   points_buf_x[1] = xoffset + x + PNT_SIZE; 
  326.   points_buf_y[1]= yoffset - (y + PNT_SIZE);
  327.   points_buf_x[2] = xoffset + x + PNT_SIZE; 
  328.   points_buf_y[2]= yoffset - (y - PNT_SIZE);
  329.   points_buf_x[3] = xoffset + x - PNT_SIZE; 
  330.   points_buf_y[3]= yoffset - (y - PNT_SIZE);
  331.   R_polygon_abs(points_buf_x, points_buf_y, 4 );
  332. }
  333.  
  334. draw_points_itriangle (x, y)
  335.   int x, y;
  336. {
  337.   GRASS_move (x - PNT_SIZE, y + PNT_SIZE);
  338.   GRASS_vector (x + PNT_SIZE, y + PNT_SIZE);
  339.   GRASS_vector (x , y - PNT_SIZE);
  340.   GRASS_vector (x - PNT_SIZE, y + PNT_SIZE);
  341. }
  342.  
  343. draw_points_fitriangle (x, y)
  344.   int x, y;
  345. {
  346.   points_buf_x[0] = xoffset + x + PNT_SIZE; 
  347.   points_buf_y[0] = yoffset - (y + PNT_SIZE);
  348.   points_buf_x[1] = xoffset + x ;           
  349.   points_buf_y[1] = yoffset - (y - PNT_SIZE);
  350.   points_buf_x[2] = xoffset + x - PNT_SIZE; 
  351.   points_buf_y[2] = yoffset - (y + PNT_SIZE);
  352.   R_polygon_abs(points_buf_x, points_buf_y, 3 );
  353. }
  354.  
  355. draw_points_triangle (x, y)
  356.   int x, y;
  357. {
  358.   GRASS_move (x - PNT_SIZE, y - PNT_SIZE);
  359.   GRASS_vector (x , y + PNT_SIZE);
  360.   GRASS_vector (x + PNT_SIZE, y - PNT_SIZE);
  361.   GRASS_vector (x - PNT_SIZE, y - PNT_SIZE);
  362. }
  363.  
  364. draw_points_ftriangle (x, y)
  365.   int x, y;
  366. {
  367.   points_buf_x[0] = xoffset + x;            
  368.   points_buf_y[0]= yoffset - (y + PNT_SIZE);
  369.   points_buf_x[1] = xoffset + x + PNT_SIZE; 
  370.   points_buf_y[1]= yoffset - (y - PNT_SIZE);
  371.   points_buf_x[2] = xoffset + x - PNT_SIZE; 
  372.   points_buf_y[2]= yoffset - (y - PNT_SIZE);
  373.   R_polygon_abs(points_buf_x, points_buf_y, 3 );
  374. }
  375.  
  376. draw_points_plus (x, y)
  377.   int x, y;
  378. {
  379.   GRASS_move (x - PNT_SIZE, y);
  380.   GRASS_vector (x + PNT_SIZE, y);
  381.   GRASS_move (x, y - PNT_SIZE);
  382.   GRASS_vector (x, y + PNT_SIZE);
  383. }
  384.  
  385. /* depends on PNT_SIZE */
  386. draw_points_octo (x, y)
  387.   int x, y;
  388. {
  389.   /* CCW */
  390.   GRASS_move (x - (int) (PNT_SIZE/3), y - PNT_SIZE);   /* 1 */
  391.   GRASS_vector (x + (int) (PNT_SIZE/3), y - PNT_SIZE); /* 2 */
  392.   GRASS_vector (x + PNT_SIZE, y - (int) (PNT_SIZE/3)); /* 3 */
  393.   GRASS_vector (x + PNT_SIZE, y + (int) (PNT_SIZE/3)); /* 4 */
  394.   GRASS_vector (x + (int) (PNT_SIZE/3), y + PNT_SIZE); /* 5 */
  395.   GRASS_vector (x - (int) (PNT_SIZE/3), y + PNT_SIZE); /* 6 */
  396.   GRASS_vector (x - PNT_SIZE, y + (int) (PNT_SIZE/3)); /* 7 */
  397.   GRASS_vector (x - PNT_SIZE, y - (int) (PNT_SIZE/3)); /* 8 */
  398.   GRASS_vector (x - (int) (PNT_SIZE/3), y - PNT_SIZE); /* 1 */
  399. }
  400.  
  401. /* depends on PNT_SIZE */
  402. draw_points_focto (x, y)
  403.   int x, y;
  404. {
  405.   /* CCW */
  406.   points_buf_x[0] = xoffset + x + (int) (PNT_SIZE/3);
  407.   points_buf_y[0] = yoffset - (y - PNT_SIZE); 
  408.   points_buf_x[1] = xoffset + x + PNT_SIZE;
  409.   points_buf_y[1] = yoffset - (y - (int) (PNT_SIZE/3)); 
  410.   points_buf_x[2] = xoffset + x + PNT_SIZE;
  411.   points_buf_y[2] = yoffset - (y + (int) (PNT_SIZE/3));
  412.   points_buf_x[3] = xoffset + x + (int) (PNT_SIZE/3);
  413.   points_buf_y[3] = yoffset - (y + PNT_SIZE); 
  414.   points_buf_x[4] = xoffset + x - (int) (PNT_SIZE/3);
  415.   points_buf_y[4] = yoffset - (y + PNT_SIZE);
  416.   points_buf_x[5] = xoffset + x - PNT_SIZE;
  417.   points_buf_y[5] = yoffset - (y + (int) (PNT_SIZE/3)); 
  418.   points_buf_x[6] = xoffset + x - PNT_SIZE;
  419.   points_buf_y[6] = yoffset - (y - (int) (PNT_SIZE/3));
  420.   points_buf_x[7] = xoffset + x - (int) (PNT_SIZE/3);
  421.   points_buf_y[7] = yoffset - (y - PNT_SIZE); 
  422.   R_polygon_abs(points_buf_x, points_buf_y, 8 );
  423. }
  424.  
  425. draw_points_x (x, y)
  426. {
  427.   GRASS_move (x - PNT_SIZE, y - PNT_SIZE);
  428.   GRASS_vector (x + PNT_SIZE, y + PNT_SIZE);
  429.   GRASS_move (x + PNT_SIZE, y - PNT_SIZE);
  430.   GRASS_vector (x - PNT_SIZE, y + PNT_SIZE);
  431. }
  432.  
  433.  
  434. /* need to fix */
  435. GRASS_arrow (sx, sy, ex, ey, head)
  436.   int sx, sy, ex, ey, head;
  437. {
  438.   do_arrow (sx, sy, ex, ey, 1);
  439.   return;
  440. }
  441.  
  442.  
  443.